package br.edu.ufc.deti.doodlematricula.negocio;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;

import br.edu.ufc.deti.doodlematricula.beans.DiaDisciplina;
import br.edu.ufc.deti.doodlematricula.beans.Horario;
import br.edu.ufc.deti.doodlematricula.beans.SolicitacoesDisciplina;
import br.edu.ufc.deti.doodlematricula.beans.Usuario;
import br.edu.ufc.deti.doodlematricula.model.PrsDisciplina;
import br.edu.ufc.deti.doodlematricula.util.Connect;

public class NgcDisciplina {
    private static NgcDisciplina instancia = null;

    private NgcDisciplina() {}

    public static NgcDisciplina getInstancia() {
        if (instancia == null) {
            instancia = new NgcDisciplina();
        }
        return instancia;
    }
	public ArrayList<SolicitacoesDisciplina> getSolicitacoesDisciplina(
			String usuario, String disciplina) throws Exception {

		ArrayList<SolicitacoesDisciplina> solicitacoes;
        Connect pool = null;
        Connection conn = null;
        try{ 
            pool = Connect.getInstancia();
            conn = pool.getConnection();
            solicitacoes = PrsDisciplina.getInstancia().getSolicitacoesDisciplina(conn, usuario, disciplina);
        } catch(Exception e) {
            throw e;
        } finally {
            pool.reciclaRecurso(conn);            
        }
        return solicitacoes;        
	}

	public ArrayList<Horario> getHorariosDisciplina() throws Exception {
		ArrayList<Horario> horarios;
        Connect pool = null;
        Connection conn = null;
        try{ 
            pool = Connect.getInstancia();
            conn = pool.getConnection();
            horarios = PrsDisciplina.getInstancia().getSolicitacoesDisciplina(conn);
        } catch(Exception e) {
            throw e;
        } finally {
            pool.reciclaRecurso(conn);            
        }
        return horarios;
	}

	public LinkedHashMap<String, LinkedHashSet<Usuario>> setSolicitacoesDisciplina( 
			String idUsuario, String idDisciplina, ArrayList<DiaDisciplina> solicitacao) throws Exception {

        Connect pool = null;
        Connection conn = null;
		LinkedHashMap<String, LinkedHashSet<Usuario>> solicitacoes;

        try{ 
            pool = Connect.getInstancia();
            conn = pool.getConnection();
            solicitacoes = PrsDisciplina.getInstancia().setSolicitacoesDisciplina(conn, idUsuario, idDisciplina, solicitacao);
        } catch(Exception e) {
            throw e;
        } finally {
            pool.reciclaRecurso(conn);            
        }
        return solicitacoes;        
	}
}
